package cn.org.eshow.webapp.action;

import cn.org.eshow.common.CommonVar;
import cn.org.eshow.common.ShopDataVar;
import cn.org.eshow.util.JacksonUtil;
import cn.org.eshow.webapp.action.response.BaseDataResponse;
import cn.org.eshow.webapp.util.RenderUtil;
import org.apache.commons.collections4.map.HashedMap;
import org.apache.commons.lang3.StringUtils;
import org.apache.struts2.convention.annotation.AllowedMethods;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * 系统API接口
 */
@AllowedMethods({"data", "bank", "feedback", "test"})
public class SystemAction extends ApiBaseAction<String> {

    private static final long serialVersionUID = 1L;

    /**
     * 基础数据列表
     */
    public void data() {
        BaseDataResponse response = new BaseDataResponse();
        String colorString = "";
        for (ShopDataVar.color color : ShopDataVar.color.values()) {
            colorString = colorString + color.toString() + ",";
        }
        response.setColors(colorString.split(","));//颜色

        String styleString = "";
        for (ShopDataVar.style style : ShopDataVar.style.values()) {
            styleString = styleString + style.toString() + ",";
        }
        response.setStyles(styleString.split(","));//风格

        String categoryString = "";
        for (ShopDataVar.category category : ShopDataVar.category.values()) {
            categoryString = categoryString + category.toString() + ",";
        }
        response.setCategorise(categoryString.split(","));//博文分类

        String productCategoryString = "";
        for (ShopDataVar.productCategory productCategory : ShopDataVar.productCategory.values()) {
            productCategoryString = productCategoryString + productCategory.toString() + ",";
        }
        response.setProductCategorise(productCategoryString.split(","));//商品分类

        Map<Integer,String> ageMap=new HashedMap<Integer,String>();
        ageMap.put(1,"0-5岁");
        ageMap.put(2,"5-10岁");
        ageMap.put(3,"10-20岁");
        ageMap.put(4,"20-30岁");
        ageMap.put(5,"30-40岁");
        ageMap.put(6,"40-50岁");

        response.setAges(ageMap);

        RenderUtil.success("获取成功", "data", response);
    }


    /**
     * 获取银行列表
     */
    public void bank() {
        List<String> responses = new ArrayList<String>();
        responses.add("中国建设银行");
        responses.add("中国农业银行");
        responses.add("中国工商银行");
        responses.add("中国银行");
        responses.add("交通银行");
        responses.add("中信银行");
        responses.add("中国平安银行");
        responses.add("兴业银行");
        responses.add("光大银行");
        responses.add("中国民生银行");
        responses.add("招商银行");
        responses.add("中国邮政储蓄银行");
        RenderUtil.success("获取成功", "banks", JacksonUtil.toJson(responses));
    }

    /**
     * 意见反馈
     */
    public void feedback() {
        String content = getRequest().getParameter("content");
        if (StringUtils.isEmpty(content)) {
            RenderUtil.failure("必须填写反馈内容");
            return;
        }
        String msg = "反馈内容：" + content;
        msg += "<br>【奶妈瞬达】";
        mailMessage.setTo(new String[]{"<xyt54321@qq.com>"});
        String subject = "奶妈瞬达";
        mailMessage.setSubject(subject);
        mailMessage.setText(msg);
        // 添加到线程中发送
        CommonVar.MAIL_SEND_LIST.add(mailMessage);
        if (!CommonVar.MAIL_SEND_LIST.isEmpty()) {
            log.debug("email already add in list");
        }
        RenderUtil.success("反馈成功");
    }

}